package com.api.cdfortis.controller;

import com.api.cdfortis.dto.*;
import com.api.cdfortis.util.WwzUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/test")
public class TestController {
    @Autowired
    private WwzUtil wwzUtil;

    /**
     * 测试一笔订单多张处方记录查询
     * @return
     */
    @ResponseBody
    @RequestMapping("/pres/get")
    public String testGetPres() {
        StringBuilder s = new StringBuilder();
        ResultDto<List> resultDto = wwzUtil.getPresFromOrderNo("1001");
        //处理接口调用结果
        if("success".equals(resultDto.getReturnCode().getValue())) {
            List<OrderPresDto> list = resultDto.getData();
            for(OrderPresDto presDto : list) {
                s.append("<p>");
                s.append("<br>----------处方------<br>");
                s.append("--处方编号--").append(presDto.getPresId()).append("</br>");
                s.append("--处方数据--");
                s.append(presDto.getRecord());
                s.append("--").append(presDto.getStatus());
                s.append("--").append(presDto.getPresId());
                s.append("--").append(presDto.getCustName());
                for(DrugDto drugDto : presDto.getDrugList()) {
                    s.append("<br>=======药品列表=====<br>");
                    s.append("--").append(drugDto.getSpec());
                    s.append("--").append(drugDto.getDrugId());
                    s.append("--").append(drugDto.getDrugCompany());
                }
                s.append("</p>");
            }
        }
        return s.toString();
    }

    /**
     * 测试药品下架
     * @return
     */
    @ResponseBody
    @RequestMapping("/drug/unload")
    public String testDrugUnload() {
         List<String> list = new ArrayList<>();
         list.add("100001");
         list.add("100002");
         list.add("100003");
         try {
             wwzUtil.unloadDrugList(list);
         } catch (Exception e) {
             e.printStackTrace();
         }
         return "success";
    }

    /**
     * 测试药品清单上传
     * @return
     */
    @ResponseBody
    @RequestMapping("/drug/upload")
    public String testDrugUpload(){
        List<DrugUploadDto> list = new ArrayList<>();
        DrugUploadDto uploadDto1 = new DrugUploadDto();
        uploadDto1.setApprNumber("国药准字");
        uploadDto1.setSpec("规则");
        uploadDto1.setPrice("1.1");
        uploadDto1.setErpId("N0001");
        uploadDto1.setDrugName("药品名称");
        uploadDto1.setFactoryName("生产厂家");
        list.add(uploadDto1);

        DrugUploadDto uploadDto2 = new DrugUploadDto();
        uploadDto2.setApprNumber("国药准字1");
        uploadDto2.setSpec("规则");
        uploadDto2.setPrice("1.1");
        uploadDto2.setErpId("N0002");
        uploadDto2.setDrugName("药品名称");
        uploadDto2.setFactoryName("生产厂家");
        list.add(uploadDto2);

        DrugUploadDto uploadDto3 = new DrugUploadDto();
        uploadDto3.setApprNumber("国药准字2");
        uploadDto3.setSpec("规则");
        uploadDto3.setPrice("1.1");
        uploadDto3.setErpId("N0003");
        uploadDto3.setDrugName("药品名称");
        uploadDto3.setFactoryName("生产厂家");
        list.add(uploadDto3);

        wwzUtil.uploadDrugList(list);
        return "success";
    }

    /**
     * 获取二维码示例
     * @return
     */
    @ResponseBody
    @RequestMapping("/getQrcode")
    public String testGetQrcode() {
        DrugQrcodeDto dto = new DrugQrcodeDto();
        dto.setErpCode("100");
        dto.setCount(1);
        DrugQrcodeDto dtoa = new DrugQrcodeDto();
        dto.setErpCode("101");
        dto.setCount(2);
        List<DrugQrcodeDto> dlist = new ArrayList();
        dlist.add(dto);
        dlist.add(dtoa);
        QrcodeDto qrcodeDto = new QrcodeDto();
        qrcodeDto.setDrugList(dlist);
        qrcodeDto.setOrderId("100000001");
        wwzUtil.getQrCode(qrcodeDto);
        return "success";
    }

    /**
     * 获得token示例
     * @return
     */
    @ResponseBody
    @RequestMapping("/getToken")
    public String testGetToken() {
        String token = wwzUtil.getToken();
        return token;
    }
}
